<template>
	<view class="page">
		<!-- 头部 start -->
		<view class="cu-custom text-white bg-white fixed" :style="[{ height: CustomBar + 'px' }]">
			<view class="cu-bar bg-white " :style="[{ height: CustomBar + 'px', paddingTop: StatusBar + 'px' }]">
				<view class="margin-left width-150 text-left" @tap="back"><text class="cuIcon-back"></text></view>
				<view class="text-lg">补仓记录</view>
				<view class="right margin-right text-right  width-150">
					<text class="text-df text-right " @click="addGoods()">{{storeHouseInfo.name}}</text>
				</view>
			</view>
		</view>
		<!-- 头部 end -->
		<fu-loading v-if="isShowLoading" class="relative" :style="[{top:CustomBar+'px'}]"></fu-loading>
		<block v-else>
			<!--商品列表 start -->
			<view class="list padding-lr-24 relative padding-bottom-150 " :style="[{top:CustomBar+'px'}]">
				<view class="flex align-center justify-around padding-top">
					<view class="text-df" :class="selectIndex==0?'text-333 active':'text-999'" @tap='selectNav(0)'>全部
					</view>
					<view class="text-df" :class="selectIndex==1?'text-333 active':'text-999'" @tap='selectNav(1)'>审核中
					</view>
					<view class="text-df" :class="selectIndex==2?'text-333 active':'text-999'" @tap='selectNav(2)'>审核失败
					</view>
					<view class="text-df" :class="selectIndex==3?'text-333 active':'text-999'" @tap='selectNav(3)'>审核成功
					</view>
				</view>
				<view class="padding-top w100">
					<view class="flex align-center margin-bottom-sm bg-white padding-sm radius-16" v-for="(item, index) in lists"
						:key="index" @tap="toDetail(item, index)">
						<view class="w100">
							<view class="flex align-center padding-bottom-sm justify-between">
								<view class="">申请时间：{{item.apply_time||""}}</view>
								<!-- 0 申请中 1审核通过  2审核拒绝  -->
								<view class="">{{ item.status | filterStatus }}</view>
							</view>
							<!-- 单个商品 -->
							<view class="goods-info flex align-center " v-if="item.goods_list&&item.goods_list.length==1">
								<block v-for="(child,key0) in item.goods_list" :key='key0'>
									<view class=" relative margin-right-sm flex-shrink fu-block-200 radius-16 overHidden">
										<view class="box-kong padding-lr-16 padding-tb-4 text-white text-sm" v-if="child.port_name">
											{{child.port_name}}
										</view>
										<fu-image :src="child.goods_thumb" mode="aspectFill"></fu-image>
									</view>
									<view class="height-200 flex  justify-between flex-direction w80">
										<view>
											<view class="text-df text-cut-2">{{ child.goods_name }}
											</view>
											<view class="text-sm text-999 margin-top-sm sku_name">
												<view class="text-cut ">
													<text>商品货号：{{ child.goods_sn }}</text>
												</view>
											</view>
										</view>
										<view class="desc-number flex justify-between align-center">
											<view class="text-lg text-prices flex-shrink">
												<text class="text-price"></text>
												<text>{{ child.shop_price||0}}</text>
											</view>
											<view class="text-sm text-999 text-cut"> 销量{{child.goods_sales_sum||0}} </view>
											<view class="text-sm text-999 text-cut"> 库存{{child.goods_stock||0}} </view>
										</view>
									</view>
								</block>
							</view>
							<!-- 多个商品 -->
							<view class="margin-top relative height-150" v-if="item.goods_list&&item.goods_list.length>1">
								<swiper class=" " :indicator-dots="false" :circular="false" :autoplay="false" @change="swiperChange">
									<swiper-item v-for="(child, key0) in item.goods_list" class="width-170 " :key="key0">
										<view class="flex align-center  bg-white  margin-right-sm ">
											<fu-image :src="child.goods_thumb||'/static/logo.png'" mode="aspectFill"
												class='fu-block-150 flex-shrink margin-right-sm radius-16 '></fu-image>
										</view>
									</swiper-item>
								</swiper>
								<view class="num-box text-theme"> 共 <view
										style=" text-orientation: sideways;	writing-mode: horizontal-tb">{{item.all_count}}</view> 件
								</view>
							</view>
							<!-- 审核失败 -->
							<!-- <view class="padding-top solid-top text-sm text-666 margin-top" v-if="item.status==2">
								{{item.remark}}
							</view> -->
							<view class="  ">
								<!-- 审核成功 -->
								<view class="flex align-center margin-top" :class="item.status==1?'justify-between':'justify-end'">
									<view class="cuIcon-delete text-lg" @tap='delItem(item)' v-if="item.status==1"></view>
									<!-- 审核中  审核成功-->
									<view class="flex align-center text-666 text-sm">
										<view class=" ">补仓数量：{{item.all_num}}</view>
									</view>
								</view>

								<!-- 审核失败 -->
								<view class="solid-top margin-top padding-top" v-if="item.status==2">
									<view class="text-left">商品未入库，请重新提交补仓申请</view>
									<view class="flex align-center justify-end text-666 text-sm margin-top-sm">
										<view class="bg-theme1 padding-lr padding-tb-6 text-white radius-100  text-sm margin-right-sm"
											@tap='toDetail(item, index)'>重新提交</view>
										<view class="cuIcon-delete text-lg" @tap.stop='delItem(item)'></view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 	<view class="action-bar padding-lr padding-bottom">
				<view class="bg-theme text-center line-height-88 height-88 text-white radius-100" @tap='applyGoods'>申请补仓
				</view>
			</view> -->
			<!--商品列表 end-->

			<fu-empty-ui v-if="lists.length == 0 && isInit" pagingListNoListDataText='暂无商品'
			></fu-empty-ui>
		</block>
		<!-- 库存输入弹框 -->
		<fu-popup v-model="isShowStock" mode="center" border-radius="16" :mask-close-able="false">
			<view class="bg-white width-560">
				<view class="text-center padding text-lg text-333">商品库存</view>
				<view class="padding-lr padding-bottom">
					<view class="  text-df text-333">库存数量</view>
					<view class="bg-f8 radius-8 padding-sm text-df margin-top">
						<input type="number" maxlength="6" placeholder="请输入库存数量" v-model="stockIpt"
							placeholder-class="text-df text-999">
					</view>
					<view class="text-sm margin-top">供应总量:1000 </view>
					<view class="text-sm margin-top-sm flex align-center justify-between">
						<text>剩余库存:1000 </text>
						<text>库存下限:1000 </text>
					</view>
				</view>
				<view class="foot solid-top flex align-center justify-between height-100">
					<view class="flex-sub text-gray solid-right text-center" @click="isShowStock=false">取消</view>
					<view class="flex-sub text-theme text-center" @click="handleConfirm">确定</view>
				</view>
			</view>
		</fu-popup>

		<!-- 断网检测组件 -->
		<fu-notwork></fu-notwork>
	</view>
</template>
<script>
	import floor from '@/common/mixin/floor';
	export default {
		mixins: [floor],
		data() {
			return {
				timer: null, // 定时器
				isEditor: false, // 管理 or 完成
				type: 1, // 悬浮按钮状态 1 页码 2 返回顶部
				isShow: false, //是否显示按钮
				totalSize: 0, // 悬浮按钮总页码
				currentPage: 1, // 当前页页码
				isShowLoading: true, // 是否显示loading
				keywords: '', // 搜索的文本
				max: 6, //
				placeholder: global.i18n['请输入商品关键字'], // 默认文本
				model: 'block', // 布局样式
				lists: [], // 结果列表
				cid: '', // 分类id(点击分类跳转过来必传)
				isInit: false, // 是否请求过数据
				status: 'more', // 加载状态
				page: 1, // 页数
				size: 10, // 页条数
				sorts: '1', // 条件
				order: 'asc', // 排序 asc: 正序 desc: 倒序
				number: '', //
				advancedSearch: null, // 高级搜索对象
				isShowStock: false, //库存弹框
				isShowAdd: false, //补仓弹框
				stockIpt: '', //库存数量
				stockItem: '', //选择的库存
				selectIndex: '0', //分类索引
				storeHouseInfo: '', //仓库信息
				order_status: 'all', //状态
				step: 1, // 1 展示配件商品 2 删除 3 添加 4 添加之后列表
			};
		},
		computed: {

		},

		onLoad(options) {
			this.storeHouseInfo = uni.getStorageSync('storehouseInfo')
			this.handleSearch(); // 搜索方法
			uni.$on('applyUpdata', data => {
				this.page = 1
				this.status = 'more'
				this.handleSearch(); // 搜索方法
			})
		},
		onPullDownRefresh() {
			this.page = 1
			this.status = 'more'
			this.handleSearch(); // 搜索方法
		},
		onReachBottom() {
			this.handleSearch(); // 搜索方法
		},
		onHide() {
			uni.$emit('applyUpdata')
		},
		methods: {
			// 滑动
			swiperChange(e) {
				// this.current = e.detail.current
			},
			// 添加商品
			addGoods() {
				this.$urouter.navigateTo({
					url: './addAccessGoods',
					params: {
						pageType: 'repair'
					}
				});
			},
			selectNav(e) {
				this.selectIndex = e
				if (e == 0) {
					this.order_status = 'all'
				} else if (e == 1) {
					this.order_status = 'apply'
				} else if (e == 2) {
					this.order_status = 'failed'
				} else if (e == 3) {
					this.order_status = 'success'
				}
				this.page = 1
				this.status = 'more'
				this.handleSearch(); // 搜索方法
			},
			delItem(item) {
				this.$util.showModal({
					title: this.i18n['提示'],
					content: '确定要删除当前内容吗?',
					confirmColor: this.$store.state.themeColor,
					success: (res) => {
						if (res.confirm) {
							this.$api.post('/v1/645a088ddfa84', {
									id: item.id
								})
								.then(res => {
									if (res.data.code == 1) {
										this.$message.info('库存不能小于0')
										setTimeout(()=>{
											this.handleSearch(); // 搜索方法
										},30)
									} else {
										this.$message.info(res.msg);
									}
								});
						}
					}
				})
			},


			openPop(item, index) {
				this.isShowStock = true
				this.stockItem = item
			},
			// 确定输入库存弹框
			handleConfirm() {
				if (this.stockIpt <= 0) {
					return this.$message.info('库存不能小于0')
				}
				// if(this.stockIpt>){
				// 	return this.$message.info('剩余库存不足')
				// }
				this.isShowStock = false
			},
			// 修改数量
			setNumber(num) {
				this.number = num;
			},
			// 一键补仓
			handleConfirmAdd() {
				this.isShowAdd = false
			},

			toDetail(item, index) {
				this.$urouter.navigateTo({
					url: './repairDetail',
					params: {
						"id": item.id,
					}
				})
			},

			/**
			 * @func 列表
			 */
			handleSearch() {
				if (this.status != 'more') return;
				this.status = 'loading';
				let data = {
					status: this.order_status, //all： 全部 apply：申请中 failed：审核失败 success：审核成功
					warehouse_id: this.storeHouseInfo.id
				};
				if (this.page == 1) {
					this.isShowLoading = true;
				}
				// 获取商品列表接口
				this.$api
					.post('/v1/63eae9d6da3cc', data)
					.then(res => {
						this.isShowLoading = false;
						if (res.data.code == 1) {
							let totalSize = res.data.data.total;
							this.totalSize = Math.ceil(totalSize / 10); // 悬浮按钮总页码
							this.currentPage = this.page; //悬浮当前页面
							let list = res.data.data.data;
							if (this.page == 1) this.lists = [];
							this.lists = this.lists.concat(list);
							this.lists.forEach(item => {
								item.show = false;
								item.checked = false;
								item.delChecked = false;
							});
							if (this.lists.length >= totalSize) {
								this.status = 'noMore';
							} else {
								this.status = 'more';
								this.page++;
							}
							this.isInit = true;
						} else {
							this.$message.error(res.data.msg);
						}
					})
					.catch(err => {
						this.isShowLoading = false;
					});
			},

			// 返回
			back() {
				uni.navigateBack();
			},

		},
		filters: {
			// 订单状态过滤器  status每个值代表的状态  0 申请中 1审核通过  2审核拒绝
			filterStatus(val) {
				switch (val) {
					case 0:
						return '审核中';
					case 1:
						return '审核成功';
					case 2:
						return '审核失败';
					default:
						return '';
				}
			},
		}
	};
</script>

<style lang="scss" scoped>
	page {
		height: 100%;
	}

	.bg-top {
		background: linear-gradient(90deg, #FFBE65 0%, #F97F33 100%);
	}

	.fixed {
		position: fixed;
		top: 0;
		width: 100%;
		z-index: 100;
	}

	.page {
		min-height: 100%;
		/* background-color: #ffffff; */
	}

	.head-top {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
	}

	.nav-bar-wrap {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
	}

	.sort-wrap {
		position: fixed;
		left: 0;
		right: 0;
	}

	.height-100 {
		height: 100rpx;
	}

	.block-180 {
		width: 180rpx;
		min-width: 180rpx;
		height: 180rpx;
		min-height: 180rpx;
		position: relative;

		image {
			width: 100%;
			height: 100%;
			border-radius: 8rpx;
		}

		.null {
			position: absolute;
			top: 0;
			right: 0;
			bottom: 0;
			left: 0;
			border-radius: 8rpx;
			background-color: rgba(0, 0, 0, 0.45);
			color: #ffffff;
			font-size: 36rpx;
			text-align: center;
			line-height: 180rpx;
		}
	}

	.list-item+.list-item {
		border-top: 1rpx solid #eeeeee;
	}

	.overlay-animate {
		position: fixed;
	}

	.float-action {
		width: 72rpx;
		height: 72rpx;
		border-radius: 50%;
		// background-color: rgba(165, 165, 165, .85);
		position: fixed;
		right: 20rpx;
		bottom: 280rpx;
		z-index: 996;
		border: 1rpx solid #cccccc;

		.cuIcon-cart {
			color: #cccccc;
		}
	}

	.animate {
		position: fixed;
		border-radius: 50%;
		z-index: 995;
		transform-origin: 50% 50%;
		transition: transform linear 0.5s, left linear 0.5s, top cubic-bezier(0.3, -0.2, 1, 0) 0.5s !important;

		image {
			width: 100rpx;
			height: 100rpx;
			border-radius: 50%;
		}
	}

	// 商品卡片line
	.fu-goods-line {
		/* min-height: 570rpx; */
		padding: 24rpx 0;
		border-radius: 24rpx;
		/* background-color: #ffffff; */
		// margin-top: 20rpx;
		display: flex;

		.block-246 {
			padding: 24rpx 24rpx 0;

			.img {
				width: 172rpx;
				height: 172rpx;
				border-radius: 6rpx;
				background-color: #eeeeee;
			}
		}

		.content {
			flex: 1;
			overflow: hidden;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
		}
	}

	// 商品卡片block
	.fu-goods-block {
		overflow: hidden;
		margin-bottom: 20rpx;
		padding: 0 10rpx;

		.wrap-box {
			background-color: #ffffff;
			border-radius: 16rpx;

			.square-wrap {
				width: 100%;
				height: 0;
				padding-bottom: 100%;
				box-sizing: border-box;
				position: relative;

				.square-box {
					position: absolute;
					left: 0;
					top: 0;
					right: 0;
					bottom: 0;
					border-radius: 24rpx 24rpx 0 0;

					image {
						width: 100%;
						height: 100%;
						border-radius: 24rpx 24rpx 0 0;
					}
				}
			}

			.image {
				width: 100%;
				border-radius: 24rpx 24rpx 0 0;
			}
		}

		.content {
			padding: 20rpx;
		}
	}

	.item-activity-label {
		padding: 2rpx 5rpx;
		/* margin: 5rpx; */
		font-size: 24rpx;
		border-radius: 6rpx;
		border: 1px solid;
		margin: 0rpx 1px 0px;
		display: inline-block;
		transform: scale(0.8);
	}

	.padding-lr-24 {
		padding: 0 24rpx;
	}

	.padding-lr-4 {
		padding: 0 4rpx;
	}

	.search-form {
		margin-left: 12rpx;
	}

	.item-goods-label {
		padding: 2rpx 8rpx;
		color: #ff6464;
		font-size: 24rpx;
		margin-right: 6rpx;
		background: rgba(255, 100, 100, 0.1);
		/* opacity: 0.1; */
		border-radius: 4rpx;
	}

	.item-activity-label {
		padding: 0 8rpx;
		height: 32rpx;
		line-height: 30rpx;
		border: 1px solid #fa2033;
		opacity: 1;
		border-radius: 4rpx;
		font-size: 20rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #fa2033;
		margin-right: 16rpx;

		&:nth-of-type(1) {
			border: 1px solid #0a7ce6;
			color: #0a7ce6;
		}
	}

	.sales-number {
		margin-top: 16rpx;
	}

	.through-price {
		margin-left: 16rpx;
		color: #bfbfbf;
	}

	.box-kong {
		position: absolute;
		border-radius: 16rpx 0 16rpx 0;
		left: 0;
		top: 0;
		z-index: 99;
		background: rgba(0, 0, 0, 0.6);
	}

	.action-bar {
		position: fixed;
		bottom: 0 !important;
		width: 100%;
		z-index: 999;
	}

	.active {
		position: relative;
	}

	.active::after {
		position: absolute;
		content: '';
		left: 0;
		right: 0;
		margin: auto;
		width: 48rpx;
		height: 4rpx;
		bottom: -10rpx;
		background: $bgtheme1;
		border-radius: 16rpx;
	}

	.num-box {
		position: absolute;
		right: 0;
		top: 0;
		height: 150rpx;
		width: 50rpx;
		background: rgba(0, 0, 0, 0.5);
		letter-spacing: 0.23em;
		writing-mode: tb-rl;
		// text-orientation: upright;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>